/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MultiView.java
 *
 * Created on Oct 23, 2009, 11:00:32 AM
 */

package projectionbuilder;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.bm.blaise.specto.space.SpaceAxes;
import org.bm.blaise.specto.space.SpaceViewObjects;
import org.bm.blaise.specto.space.basic.SpaceBox;

/**
 *
 * @author ae3263
 */
public class MultiView extends javax.swing.JFrame
        implements ChangeListener {

    SpaceAxes axes;
    SpaceBox box1, box2;
    SpaceViewObjects svo1, svo2;
    ProjectedPointGenerator ppg;

    /** Creates new form MultiView */
    public MultiView() {
        initComponents();

        spacePlot1.getProjection().setCamSep(0.02);
        spacePlot2.getProjection().setCamSep(0.02);
        spacePlot3.getProjection().setCamSep(0.02);

        spacePlot1.getProjection().setDpi(200);
        spacePlot1.getProjection().setScreenDist(5.0);
        spacePlot1.getProjection().setViewDist(10.0);
        spacePlot2.getProjection().setDpi(200);
        spacePlot2.getProjection().setScreenDist(5.0);
        spacePlot2.getProjection().setViewDist(10.0);
        spacePlot3.getProjection().setDpi(200);
        spacePlot3.getProjection().setScreenDist(5.0);
        spacePlot3.getProjection().setViewDist(20.0);

        axes = new SpaceAxes();
        box1 = new SpaceBox();
        box2 = new SpaceBox();
        svo1 = new SpaceViewObjects(spacePlot1.getProjection());
        svo2 = new SpaceViewObjects(spacePlot2.getProjection());
        ppg = new ProjectedPointGenerator(spacePlot1, spacePlot2);
        ppg.setVisible(false);

        spacePlot1.addPlottable(axes);
        spacePlot1.addPlottable(box1);

        spacePlot2.addPlottable(axes);
        spacePlot2.addPlottable(box1);

        spacePlot3.addPlottable(axes);
        spacePlot3.addPlottable(box2);
        spacePlot3.addPlottable(svo1);
        spacePlot3.addPlottable(svo2);
        spacePlot3.addPlottable(ppg);

        spacePlot1.getVisometry().addChangeListener(this);
        spacePlot2.getVisometry().addChangeListener(this);
        spacePlot3.getVisometry().addChangeListener(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        modeGroup = new javax.swing.ButtonGroup();
        jSplitPane1 = new javax.swing.JSplitPane();
        spacePlot3 = new org.bm.blaise.specto.space.SpacePlotComponent();
        jSplitPane2 = new javax.swing.JSplitPane();
        spacePlot1 = new org.bm.blaise.specto.space.SpacePlotComponent();
        spacePlot2 = new org.bm.blaise.specto.space.SpacePlotComponent();
        jToolBar1 = new javax.swing.JToolBar();
        anaglyphButton = new javax.swing.JToggleButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        schematicMode = new javax.swing.JToggleButton();
        reconstructMode = new javax.swing.JToggleButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setResizeWeight(0.5);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, anaglyphButton, org.jdesktop.beansbinding.ELProperty.create("${selected}"), spacePlot3, org.jdesktop.beansbinding.BeanProperty.create("anaglyph"));
        bindingGroup.addBinding(binding);

        org.jdesktop.layout.GroupLayout spacePlot3Layout = new org.jdesktop.layout.GroupLayout(spacePlot3);
        spacePlot3.setLayout(spacePlot3Layout);
        spacePlot3Layout.setHorizontalGroup(
            spacePlot3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 398, Short.MAX_VALUE)
        );
        spacePlot3Layout.setVerticalGroup(
            spacePlot3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 132, Short.MAX_VALUE)
        );

        jSplitPane1.setLeftComponent(spacePlot3);

        jSplitPane2.setResizeWeight(0.5);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, anaglyphButton, org.jdesktop.beansbinding.ELProperty.create("${selected}"), spacePlot1, org.jdesktop.beansbinding.BeanProperty.create("anaglyph"));
        bindingGroup.addBinding(binding);

        org.jdesktop.layout.GroupLayout spacePlot1Layout = new org.jdesktop.layout.GroupLayout(spacePlot1);
        spacePlot1.setLayout(spacePlot1Layout);
        spacePlot1Layout.setHorizontalGroup(
            spacePlot1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 195, Short.MAX_VALUE)
        );
        spacePlot1Layout.setVerticalGroup(
            spacePlot1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 134, Short.MAX_VALUE)
        );

        jSplitPane2.setLeftComponent(spacePlot1);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, anaglyphButton, org.jdesktop.beansbinding.ELProperty.create("${selected}"), spacePlot2, org.jdesktop.beansbinding.BeanProperty.create("anaglyph"));
        bindingGroup.addBinding(binding);

        org.jdesktop.layout.GroupLayout spacePlot2Layout = new org.jdesktop.layout.GroupLayout(spacePlot2);
        spacePlot2.setLayout(spacePlot2Layout);
        spacePlot2Layout.setHorizontalGroup(
            spacePlot2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 196, Short.MAX_VALUE)
        );
        spacePlot2Layout.setVerticalGroup(
            spacePlot2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 134, Short.MAX_VALUE)
        );

        jSplitPane2.setRightComponent(spacePlot2);

        jSplitPane1.setBottomComponent(jSplitPane2);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        jToolBar1.setRollover(true);

        anaglyphButton.setText("Anaglyph");
        anaglyphButton.setFocusable(false);
        anaglyphButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        anaglyphButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, spacePlot1, org.jdesktop.beansbinding.ELProperty.create("${anaglyph}"), anaglyphButton, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        jToolBar1.add(anaglyphButton);
        jToolBar1.add(jSeparator1);

        modeGroup.add(schematicMode);
        schematicMode.setSelected(true);
        schematicMode.setText("Schematic");
        schematicMode.setFocusable(false);
        schematicMode.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        schematicMode.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        schematicMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                schematicModeActionPerformed(evt);
            }
        });
        jToolBar1.add(schematicMode);

        modeGroup.add(reconstructMode);
        reconstructMode.setText("Reconstruct");
        reconstructMode.setFocusable(false);
        reconstructMode.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        reconstructMode.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        reconstructMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reconstructModeActionPerformed(evt);
            }
        });
        jToolBar1.add(reconstructMode);
        jToolBar1.add(jSeparator2);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void reconstructModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reconstructModeActionPerformed
        box2.setVisible(false);
        svo1.setVisible(false);
        svo2.setVisible(false);
        ppg.setVisible(true);
    }//GEN-LAST:event_reconstructModeActionPerformed

    private void schematicModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schematicModeActionPerformed
        box2.setVisible(true);
        svo1.setVisible(true);
        svo2.setVisible(true);
        ppg.setVisible(false);
    }//GEN-LAST:event_schematicModeActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MultiView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton anaglyphButton;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.ButtonGroup modeGroup;
    private javax.swing.JToggleButton reconstructMode;
    private javax.swing.JToggleButton schematicMode;
    private org.bm.blaise.specto.space.SpacePlotComponent spacePlot1;
    private org.bm.blaise.specto.space.SpacePlotComponent spacePlot2;
    private org.bm.blaise.specto.space.SpacePlotComponent spacePlot3;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public void stateChanged(ChangeEvent e) {
        spacePlot1.repaint();
        spacePlot2.repaint();
        spacePlot3.repaint();
    }

}
